/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package solitairetest;

import java.awt.datatransfer.*;
import java.io.*;
import java.util.*;
import java.util.List;

import solitairetest.logic.*;

/**
 *
 * @author Administrator
 */
public class DeckTransferable implements Transferable, ClipboardOwner
{
    public static DataFlavor cardFlavor = null;
    public static DataFlavor localCardFlavor = null;

    private Deck deck;

    static
    {
        try
        {
            cardFlavor = new DataFlavor(solitairetest.logic.Deck.class, "Non local card");
            localCardFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=solitairetest.logic.Deck", "Local card");
        }
        catch (Exception e)
        {
            System.err.println(e);
        }
    }

    public DeckTransferable(Deck deck)
    {
        this.deck = deck;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor)
    {
        return flavor.equals(cardFlavor) || flavor.equals(localCardFlavor);
    }

    public synchronized DataFlavor[] getTransferDataFlavors()
    {
        DataFlavor[] dataFlavors = new DataFlavor[2];
        dataFlavors[0] = this.cardFlavor;
        dataFlavors[1] = this.localCardFlavor;

        return dataFlavors;
    }

    public Object getTransferData(DataFlavor flavor)
            throws UnsupportedFlavorException, IOException
    {
        if (flavor.equals(cardFlavor) || flavor.equals(localCardFlavor))
        {
            return deck;
        }
        else
            throw new UnsupportedFlavorException(flavor);
    }

    public void lostOwnership(Clipboard clipboard, Transferable contents)
    {
        System.out.println("CardTransferable lost ownership of " +
                clipboard.getName());
        System.out.println("data: " + contents);
    }
}
